package com.mall.shop.Result;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.ToString;


@ToString
public class Result {

    @JsonProperty("code")
    private int code;

    @JsonProperty("msg")
    private String message;

    @JsonProperty("data")
    private Object data;

    public Result setCode(ResultCode resultCode) {
        this.code = resultCode.code();
        return this;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public Result setMessage(String message) {
        this.message = message;
        return this;
    }

    public Object getData() {
        return data;
    }

    public Result setData(Object data) {
        this.data = data;
        return this;
    }

    public static Result success(String message) {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS);
        result.setMessage(message);
        return result;
    }

    public static Result success() {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS);
        result.setMessage("SUCCESS");
        return result;
    }

    public static Result error(String message) {
        Result result = new Result();
        result.setCode(ResultCode.FAIL);
        result.setMessage(message);
        return result;
    }

    public static Result error(ResultCode code,String message) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS);
        result.setMessage("SUCCESS");
        result.setData(data);
        return result;
    }

    public static Result success(Object data, String message) {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS);
        result.setMessage(message);
        result.setData(data);
        return result;
    }
}
